﻿using Microsoft.Practices.Unity;
using System;

namespace UnityLearning
{
    class Program
    {
        static void Main(string[] args)
        {
            // 创建简单单例
            IUnityContainer container = new UnityContainer();//1、定义一个空容器
            container.RegisterInstance<IStudent>(new Student() { Name = "张三" });
            Console.WriteLine(container.Resolve<IStudent>().Name);
            container.RegisterInstance<IStudent>(new Student() { Name = "李四" });
            Console.WriteLine(container.Resolve<IStudent>().Name);

            // 按照type注册
            container.RegisterType<IStudent,Student>();
            container.Resolve<IStudent>().Learn("按照type注册");

            // 按照名称注册
            container.RegisterInstance<IStudent>("领导",new Student() { Name = "张三" });
            Console.WriteLine(container.Resolve<IStudent>("领导").Name);
            container.RegisterInstance<IStudent>("领导", new Student() { Name = "李四" });
            Console.WriteLine(container.Resolve<IStudent>("领导").Name);
        }
    }
}
